/**
 * 
 */
package org.whuims.pois.common;

/**
 * @author Administrator
 *
 */

/*
 * This is a general object used to manage the connection and operation
 * to various database. All the critical information used for connecting
 * is stored in DBConfig.property.
 */

import java.sql.*;

public class DBConnection {

	private Connection conn;

	public DBConnection() {
		conn = null;
	}

	public Connection getConn() {
		try {
			String MySqlDriver = "com.mysql.jdbc.Driver";
			//String dbName = PropertiesReader.getValueByKey("dbName");
			String dbName = "poms";
			String dbUser = "root";
			String dbpwd = "irlab2013";
			//String dbpwd = PropertiesReader.getValueByKey("dbpwd");
			String MySqlURL = "jdbc:mysql://202.114.70.31:3306/"+ dbName+"?user="+dbUser+"&password="+dbpwd+"&useUnicode=true&characterEncoding=utf-8";
			Class.forName(MySqlDriver).newInstance();
			conn = DriverManager.getConnection(MySqlURL);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		DBConnection DBConn = new DBConnection();
		try {
			Connection Conn = DBConn.getConn();

			if (Conn != null)
				System.out.println("true");
			else
				System.out.println("wrong");
		}

		catch (Exception e) {
			System.out.println(e.getMessage().toString());
		}
	}

}
